package com.aaa.member.controller.api;

import com.aaa.entity.Coupon;
import com.aaa.member.service.CouponService;
import com.aaa.security.annotation.HasPermission;
import com.aaa.security.annotation.MyLog;
import com.aaa.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;

/**
 * @author JYH
 * @version 1.0
 * @date 2023/3/2 10:45
 */
@Api(value = "/member/api/coupon", tags = {"优惠券"})
@RestController
@RequestMapping("/member/api/coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

/**
 * @author JYH
 * @date 2023/3/2 11:35
 * @description - 分页查询所有优惠券
 * @param currentPage
 * @param pageSize
 * @param name
 */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "name", value = "", required = true)
    })
    @ApiOperation(value = "- 分页查询所有优惠券", notes = "- 分页查询所有优惠券", httpMethod = "POST")
    @MyLog(title="查询优惠券")
    @PostMapping("/selectAll")
    @HasPermission(value = "coupon:search")
    public Result selectAll(Integer currentPage,Integer pageSize , String name){
        return couponService.selectAll(currentPage,pageSize,name);
    }

    /**
     * @author JYH
     * @date 2023/3/2 11:40
     * @description - 添加优惠券
     * @param coupon
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Coupon", name = "coupon", value = "", required = true)
    })
    @ApiOperation(value = "- 添加优惠券", notes = "- 添加优惠券", httpMethod = "POST")
    @MyLog(title="添加优惠券")
    @PostMapping("/add")
    @HasPermission(value = "coupon:insert")
    public Result add(@RequestBody Coupon coupon){
        return couponService.add(coupon);
    }

    /**
     * @author JYH
     * @date 2023/3/2 15:50
     * @description - 查询所有的门店
     * @param
     */
    @ApiOperation(value = "- 查询所有的门店", notes = "- 查询所有的门店", httpMethod = "GET")
    @MyLog(title="查询门店")
    @GetMapping("/selectShops")
    public Result selectShop(){
        return couponService.selectShops();
    }

    /**
     * @author JYH
     * @date 2023/3/2 17:28
     * @description - 修改会员优惠券
     * @param coupon
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Coupon", name = "coupon", value = "", required = true)
    })
    @ApiOperation(value = "- 修改会员优惠券", notes = "- 修改会员优惠券", httpMethod = "POST")
    @MyLog(title="修改优惠券")
    @PostMapping("/update")
    @HasPermission(value = "coupon:update")
    public Result update(@RequestBody Coupon coupon){
        return new Result(2000,"成功", couponService.updateById(coupon));
    }

    /**
     * @author JYH
     * @date 2023/3/2 18:50
     * @description - 删除会员优惠券
     * @param id
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "long", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "- 删除会员优惠券", notes = "- 删除会员优惠券", httpMethod = "DELETE")
    @MyLog(title="删除优惠券")
    @DeleteMapping("/delete")
    @HasPermission(value = "coupon:delete")
    public Result delete(long id){
        return new Result(2000,"成功",couponService.delete(id));
    }
}
